package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection();){
            Statement statement = connection.createStatement();
            String sql="SELECT s.id,s.name,s.job,c.name,c.floor "+
                    "FROM student s "+
                    "JOIN class c ON s.class+id=c.id "+
                    "WHERE c.name='1年级1班'";
            ResultSet resultSet=statement.executeQuery(sql);
            while(resultSet.next()){
                int sId = resultSet.getInt("s.id");
                String sName = resultSet.getString("s.name");
                String job = resultSet.getString("s.job");
                String cName = resultSet.getString("c.name");
                int floor = resultSet.getInt("c.floor");
                System.out.println(sId+","+sName+","+job+","+cName+","+floor);

            }
    } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }}
